let python_highlight_all = 1

" au Filetype go,javascript,python,vim,shell,ruby,c,css,html setlocal synmaxcol=200

autocmd FileType python syn keyword pythonDecorator True None False self
autocmd BufNewFile,BufRead *.jinja set syntax=htmljinja
autocmd BufNewFile,BufRead *.mako set ft=mako

" autocmd FileType python map <buffer> F :set foldmethod=indent<cr>
autocmd FileType python set cindent
autocmd FileType python set cinkeys-=0#
autocmd FileType python set indentkeys-=0#

" quick quit
autocmd FileType help nnoremap <buffer> <silent> gq :close<cr>
autocmd FileType qf nnoremap <buffer> <silent> gq :cclose<cr>:lclose<cr>
autocmd FileType git nnoremap <buffer> <silent> gq :close<cr>
autocmd FileType vim nnoremap <buffer> <silent> gq :bd!<cr>
autocmd FileType netrw nnoremap <buffer> <silent> gq :close<cr>
autocmd FileType fugitive nnoremap <buffer> <silent> gq :q<cr>
autocmd FileType gitcommit nnoremap <buffer> <silent> gq :wq<cr>
autocmd FileType agrep nnoremap <buffer> <silent> gq :q<cr>
autocmd FileType man nnoremap <buffer> <silent> gq :q<cr>

" file templates
autocmd BufNewFile *.py 0r $vimroot/user/plugins/vim-templates/python.tpl
autocmd BufNewFile *.sh 0r $vimroot/user/plugins/vim-templates/bash.tpl
autocmd BufNewFile *.c  0r $vimroot/user/plugins/vim-templates/c.tpl

" Replace $(date '+%Y-%m-%d') with actual date when loading .c files
autocmd BufNewFile *.c silent! %s/$(date '+%Y-%m-%d')/\=strftime('%Y-%m-%d')/g

" for vim-commentary
autocmd FileType python,shell,coffee set commentstring=#\ %s
autocmd FileType java,cpp,proto set commentstring=//\ %s

" for golang
autocmd FileType go noremap <buffer> <silent> [[ ?^func\><cr>
autocmd FileType go noremap <buffer> <silent> ]] /^func\><cr>

" for c
autocmd FileType c,cpp set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab

" for markdown
autocmd FileType markdown nmap <buffer><silent> <space>pp :call mdip#MarkdownClipboardImage()<CR>
autocmd InsertLeave *.md write
autocmd FocusLost *.md if &mod | write | endif

" for man
autocmd FileType man nmap <silent> gd <c-]>

function! s:golang_settings() abort
    setlocal noexpandtab

    let g:go_def_mapping_enabled = 0
    let g:go_code_completion_enabled = 0
    let g:go_gopls_enabled = 0
    let g:go_doc_keywordprg_enabled = 0
    let g:go_diagnostics_enabled = 0

    let g:go_snippet_engine = ''
    let g:go_highlight_trailing_whitespace_error = 0
    let g:go_play_open_browser = 1
    let g:go_fmt_command = 'goimports'

    " nnoremap <buffer><Space>i :<C-u>Unite go/import -start-insert<CR>
    " nnoremap <buffer><Leader>i :<C-u>GoImports<CR>
    " inoremap <buffer><C-g><C-i> <C-o>:GoImports<CR>
    " nnoremap <buffer><Leader>gt :<C-u>GoTestFunc<CR>
    " nnoremap <buffer><Leader>gr :<C-u>GoRename<Space>
    " nnoremap <buffer><Leader>gi :<C-u>execute 'GoImport' expand('<cword>')<CR>
    " nnoremap <buffer><Leader>gn :<C-u>GoSameIds<CR>
    " command! -buffer -nargs=0 -bar GoToggleAccess call <SID>toggle_access()
endfunction

autocmd FileType go call s:golang_settings()
